package com.junmeng.jdemo.recycler.chat.viewbinding;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewbinding.ViewBinding;

import com.example.common.recycler.viewbinding.BaseViewBindingBindView2;
import com.example.common.recycler.viewbinding.ViewBindingViewHolder;
import com.junmeng.jdemo.R;
import com.junmeng.jdemo.databinding.ItemChatImageReceiveBinding;
import com.junmeng.jdemo.databinding.ItemChatImageSendBinding;
import com.junmeng.jdemo.recycler.chat.IKind;

public class BindViewImage extends BaseViewBindingBindView2<BindViewImage.Item, ViewBinding> {

    @Override
    public ViewBinding getBinding(@NonNull View itemView, Item item) {
        if (item.getKind() == 0) {
            return ItemChatImageReceiveBinding.bind(itemView);
        } else {
            return ItemChatImageSendBinding.bind(itemView);
        }
    }

    @Override
    public int getItemLayoutResId(Item item) {
        int layoutResId;
        if (item.getKind() == 0) {
            layoutResId = R.layout.item_chat_image_receive;
        } else {
            layoutResId = R.layout.item_chat_image_send;
        }
        return layoutResId;
    }

    @Override
    public void bindViewDataWithFull(ViewBindingViewHolder holder, int position, Item item) {
        if (item.getKind() == 0) {
            ItemChatImageReceiveBinding viewholder = (ItemChatImageReceiveBinding) holder.binding;
            viewholder.image.setImageResource(R.drawable.emoji85);
        } else {
            ItemChatImageSendBinding viewholder = (ItemChatImageSendBinding) holder.binding;
            viewholder.image.setImageResource(R.drawable.emoji1);
        }
    }


    public static class Item implements IKind {

        public Item(int kind) {
            this.kind = kind;
        }

        public Item(int kind, String text) {
            this.kind = kind;
            this.text = text;
        }

        int kind;

        public String text;

        @Override
        public void setKind(int kind) {
            this.kind = kind;
        }

        @Override
        public int getKind() {
            return kind;
        }
    }

}
